package com.lz.ovuola.util.threadlocal;

import java.util.ArrayList;
import java.util.List;

import com.lz.ovuola.util.constant.DataSourceConsts;

public class DataSourceHolder {

	// 线程本地环境
	private static final ThreadLocal<String> dataSources = new ThreadLocal<String>();

	private static final List<String> dataSourcesNames = new ArrayList<String>() {

		private static final long serialVersionUID = -7539786489841743864L;
		{
			add(DataSourceConsts.PRIMARY_DS);
			add(DataSourceConsts.SECONDARY_DS);
		}
	};

	private DataSourceHolder() {
		super();
		// TODO Auto-generated constructor stub
	}

	// 设置数据源
	public static void setDataSource(String customerType) {
		dataSources.set(customerType);
	}

	// 获取数据源
	public static String getDataSource() {
		return (String) dataSources.get();
	}

	// 清除数据源
	public static void clearDataSource() {
		dataSources.remove();
	}

	public static boolean containsDataSource(String dataSourceId) {
		return dataSourcesNames.contains(dataSourceId);
	}
}